home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / util / text / tex.lha / MegaED / Trans / TeX.trans.c < prev    next >
C/C++ Source or Header  |  1995-08-03  |  2KB  |  111 lines

  1. /*
  2. ** PasTeX.trans: Konvertiert PasTeX Fehlerausgaben für MegaEd
  3. ** von Sven Fischer, herpes@kawo2.rwth-aachen.de, 100% PD
  4. */
  5.  
  6. #include <exec/memory.h>
  7. #include <dos/dos.h>
  8. #include <dos/dostags.h>
  9. #include <string.h>
  10.  
  11. int main(void)
  12. {
  13.  const char *file1="T:MegaEdMake-ErrFile";
  14.  const char *file2="T:MegaEdMake-Errors";
  15.  BPTR con;
  16.  BPTR fileh;
  17.  char *old=NULL,*new=NULL;
  18.  char *off, *off2, *dest, *warn, *last;
  19.  LONG len;
  20.  short i;
  21.  BOOL errors=FALSE;
  22.  
  23.  if(!(fileh=Open(file1,MODE_OLDFILE))) return;
  24.  Seek(fileh,0,OFFSET_END);
  25.  len=Seek(fileh,0,OFFSET_BEGINNING);
  26.  if(len)
  27.  {
  28.   if(!(old=(char*)AllocVec(len+1,MEMF_PUBLIC)))
  29.    {Close(fileh); return;}
  30.   if(Read(fileh,old,len)!=len)
  31.    {FreeVec(old); Close(fileh); return;}
  32.  }
  33.  Close(fileh);
  34.  if(!len) return;
  35.  old[len]=0;
  36.  
  37.  if(!(new=(char*)AllocVec(len+1,MEMF_PUBLIC))) return;
  38.  
  39.  off=old;
  40.  dest=new;
  41.  for(i=0;i<2;i++)
  42.  {
  43.   if(!(off=strchr(off,10))) goto esc;
  44.   off++;
  45.  }
  46.  for(;;)
  47.  {
  48.   warn=off;
  49.   off=strstr(off,"! ");
  50.   off2=strstr(warn,"full");
  51.   if(!off && !off2) break;
  52.   printf("off %ld off2 %ld\n",off,off2);
  53.   if(!off || (off2 && (ULONG)off2 < (ULONG)off))
  54.   {
  55.      off=off2-6;                                   /* ||  diesen Teil auskommentieren */
  56.      *dest='W';                                    /* ||  um keine Warnings zu bekommen */
  57.      dest++;                                       /* \/  (siehe readme) */
  58.      off2=strchr(off,10)+1;
  59.      for(;*off2==10;off2++);
  60.      off=strstr(off,"lines")+6;
  61.      for(;isdigit(*off);off++,dest++) *dest=*off;
  62.      *dest='/'; dest++;
  63.      *dest='1'; dest++;
  64.      *dest=10; dest++;
  65.      *off=0;
  66.      strcpy(dest,off2);
  67.      off2+=strlen(off2)+1;
  68.      dest+=strlen(dest);
  69.      *dest=10;                                     /* /\ */
  70.      dest++;                                       /* || */
  71.      off=off2;                                     /* || */
  72.   }
  73.   else
  74.   {
  75.      *dest='E';
  76.      dest++;
  77.      off2=strchr(off,10)+3;
  78.      *(off2-3)=0;
  79.      off+=2;
  80.      for(;isdigit(*off2);off2++,dest++) *dest=*off2;
  81.      *dest='/'; dest++;
  82.      *dest='1'; dest++;
  83.      *dest=10; dest++;
  84.      strcpy(dest,off);
  85.      off+=strlen(off)+3;
  86.      dest+=strlen(dest);
  87.      *dest=10;
  88.      dest++;
  89.   }
  90.   errors=TRUE;
  91.   last=dest;
  92.  
  93.   if(!*off) break;
  94.  }
  95.  esc:
  96.  if(errors)
  97.  {
  98.   if(fileh=Open(file2,MODE_NEWFILE))
  99.   {
  100.    len=(LONG)last-(LONG)new;
  101.    Write(fileh,new,len);
  102.    Close(fileh);
  103.   }
  104.  }
  105.  else DeleteFile(file2);
  106.  if(old) FreeVec(old);
  107.  if(new) FreeVec(new);
  108.  return(0);
  109. }
  110.  
  111.